var showCancelOrderWin = function(orderId,orderNum,btnId){//取消订单窗口
    $("#cancelBox > .layer > h2").html("取消订单");
    $("#cancelBox").find(".msg").html("您确定取消订单");
    $("#cancelBox").find(".orderNum").html(orderNum);
    var hrefJs =  "javascript:cancelOrder("+orderId+","+btnId+");";
    $("#cancelBox").find(".determine").attr("href",hrefJs);
    easyDialog.open({container : 'cancelBox',fixed : false});
}
var showBuyerSignedWin = function(orderId,orderNum,btnId){//确认收货
    $("#cancelBox > .layer > h2").html("确认收货");
    $("#cancelBox").find(".msg").html("您确认收货");
    $("#cancelBox").find(".orderNum").html(orderNum);
    var hrefJs =  "javascript:buyerSigned("+orderId+","+btnId+");";
    $("#cancelBox").find(".determine").attr("href",hrefJs);
    easyDialog.open({container : 'cancelBox',fixed : false});
}
var cancelOrder = function(orderId,btnId){//取消订单操作
    $("#cancelBox_success > .layer > h2").html("取消订单");
    $("#cancelBox_success").find(".msg").html("订单取消成功！");
    $.ajaxSettings['contentType'] = "application/x-www-form-urlencoded; charset=utf-8;";
    $.ajax({
        type:"GET",
        url:dataValue.webRoot+"/order/cancel.json?orderId="+orderId ,
        success:function(data) {
            if (data.success == "true") {
                easyDialog.open({container : 'cancelBox_success',fixed : false,autoClose : 2000,callback : function(){
                    window.location.reload();
                }});
                $(btnId).hide();
            }
        },
        error:function(XMLHttpRequest, textStatus) {
            memberShowTip("取消订单失败！");
        }
    });
}
var buyerSigned = function(orderId,btnId){//确认收货
    $("#cancelBox_success > .layer > h2").html("确认收货");
    $("#cancelBox_success").find(".msg").html("确认收货成功！");
    $.ajaxSettings['contentType'] = "application/x-www-form-urlencoded; charset=utf-8;";
    $.ajax({
        type:"GET",
        url:dataValue.webRoot+"/order/buyerSigned.json?orderId="+orderId ,
        success:function(data) {
            if (data.success == "true") {
                easyDialog.open({container : 'cancelBox_success',fixed : false,autoClose : 2000,callback : function(){
                    window.location.reload();
                }});
                $(btnId).hide();
            }
        },
        error:function(XMLHttpRequest, textStatus) {
            memberShowTip("取消订单失败！");
        }
    });
}
var buyAgain = function(orderId){
    $.ajaxSettings['contentType'] = "application/x-www-form-urlencoded; charset=utf-8;";
    $.ajax({
        type:"GET",url:dataValue.webRoot+"/cart/buyAgain.json?orderId="+orderId ,
        success:function(data){
            if (data.success == "true") {
                memberShowTip("再次购买成功，<a style='color:#0066CC' href='"+dataValue.webRoot+"/shoppingcart/cart.ac' target='_blank'>请到购物车查看>></a>")
            }else{
                memberShowTip("再次购买失败！<div></div>")
            }
        }
    });
}
var indexTabChannel = function(tabId,divClass){//tab切换
    $(tabId).parents(".minute-menu").find("a").removeClass("cur");
    $(tabId).addClass("cur");
    if(divClass == '.newOrderDiv'){
        $('.productCollect').hide();
    }
    if(divClass == '.productCollect'){
        $('.newOrderDiv').hide();
    }
    $(divClass).fadeIn(500);
}
var showTip = function(){//门店积分兑换
    if(dataValue.erpIntegral == 0){
        easyDialog.open({container : 'erpIntegralWin',fixed : false,autoClose : 5000});
        return;
    }
    easyDialog.open({container : 'shoppingCartTip',fixed : false});
}
var integralHandle = function (){
    checkIntegral();
    $("#successIntegral").html(parseFloat(($("#changeIntegral").val() == '' ? 0 : $("#changeIntegral").val()) * dataValue.integralRatio).toFixed(2))
}
var checkIntegral = function(){
    var param= /^[1-9]\d*$/;

    if($("#changeIntegral").val() != "" && $("#changeIntegral").val() > 0){
        if(!param.test($("#changeIntegral").val())){
            memberShowTip("请输入正整数的积分数值");
            $("#changeIntegral").val("0");
            return false;
        }
        if($("#changeIntegral").val() > dataValue.erpIntegral){
            memberShowTip("您的最大转换积分数为： "+dataValue.erpIntegral+"，请重新输入");
            $("#changeIntegral").val("0");
            return false;
        }
    }
    return true;
}

var postErp = function(){
    if(!checkIntegral()){
        return;
    }

    if($("#changeIntegral").val() == ""){
        memberShowTip("请输入需要转换的积分数值");
        return;
    }

    if($("#changeIntegral").val() == 0){
        memberShowTip("转换积分数值不能为0！");
        return;
    }
    $.ajaxSettings['contentType'] = "application/x-www-form-urlencoded; charset=utf-8;";
    $.ajax({
        type:"GET",
        url:"${webRoot}/member/ydtCopy/integralExchange.json",
        data:{integral:$("#changeIntegral").val(),addIntegral : $("#successIntegral").html()},
        dataType: "json",
        async: false,//同步
        success:function(data) {
            if(data.success == 'true'){
                memberShowTip("积分转换成功！");
                goToUrl("${webRoot}/module/member/myIntegral.ac");
            }
        },
        error:function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                memberShowTip(result.jsonError.errorText);
            }
        }
    });

}
